package problem3;

//3.无重复字符的最长子串
//https://leetcode.cn/problems/longest-substring-without-repeating-characters/?envType=study-plan-v2&envId=top-100-liked

class Solution {
    public int lengthOfLongestSubstring(String s) {
        if(s.length() == 0) return 0;
        int ret = 0;
        int[] hash = new int[256];
        for(int i = 0, j = 0; j<s.length(); j++) {
            hash[s.charAt(j)]++;
            while(i<j && hash[s.charAt(j)] > 1) {
                hash[s.charAt(i)]--;
                i++;
            }
            ret = Math.max(ret, j-i+1);
        }
        return ret;
    }
}